<template>
  <div id="app">
    <loading v-cloak v-if="loadingShow" style="margin-top:210px;"></loading>
    <!-- 顶栏 -->
    <keep-alive>
      <NavView v-show="headerShow" v-cloak></NavView>
    </keep-alive>
    <!-- 主体内容 -->
    <router-view></router-view>
    <!-- <HomeView></HomeView> -->
    <!-- 页脚内容 -->
    <!-- <FootView v-show="footerShow"></FootView> -->
    <control v-cloak></control>
  </div>
</template>

<script>
import NavView from './components/NavView.vue'
// import HomeView from './components/HomeView.vue'
import FootView from './components/FootView.vue'

import loading from './components/loading/Loading.vue'
import control from './components/control.vue'

import { mapActions, mapGetters } from 'vuex'

export default {
  name: 'app',
  computed: mapGetters([
    'headerShow',
    'loadingShow',
    'footerShow',
    'logState',
    'hash'
  ]),
  methods: mapActions([]),
  components: {
    NavView,
    loading,
    // HomeView,
    FootView,
    control
  },
  watch: {//当路由发生变化的是时候
    $route(to, from) {
      // 拦截要前往的路由
      if (to.path == '/home') {
        this.$store.dispatch('showfooter')
        this.$store.dispatch('showheader')
      }else if(to.path == '/kernel'){
        this.$store.dispatch('hideheader')
      }
    }
  },
  created() {
    mui.back = function() {
      var first = null;
      mui.back = function() {
        if (!first) {//首次按键，提示‘再按一次退出应用’
          first = (new Date()).getTime();
          mui.toast('再按一次退出应用');
          setTimeout(function() {
            first = null;
          }, 1000);
        } else {
          if ((new Date()).getTime() - first < 1000) {
            // var main = plus.android.runtimeMainActivity();
            // main.moveTaskToBack(false);
            plus.runtime.quit();
          }
        }
      };
    }
  },
  methods: {
  }
}
</script>

<style scoped>
[v-cloak] {
  display: none;
}
</style>
